<template>

  <div>
    <h1>这是列表页面</h1>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          prop="id"
          label="编号"
         >
      </el-table-column>
      <el-table-column
          prop="day"
          label="日期"
         >
      </el-table-column>
      <el-table-column
          prop="time"
          label="时间">
      </el-table-column>
      <el-table-column
          prop="reservationNumber"
          label="预约人数">
      </el-table-column>
      <el-table-column
          prop="surplusNumber"
          label="可预约人数">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row.id)" type="text" size="small">预约</el-button>
          <el-button v-if="roleData=='0'" @click="showByid(scope.row)" type="text" size="small">修改预约人数</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>

    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <el-form :model="formData">
        <el-form-item label="活动名称" :label-width="formLabelWidth">
          <el-input v-model="formData.surplusNumber" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary"  @click="UpdateHistory()">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import {hospitalList,hospitalReser,hospitalUpdata} from "@/api/userApi";

export default {
  data() {
    return {
      formLabelWidth: '120px',
      dialogFormVisible: false,
      roleData:"",
      tableData: [],
      form: {
        pageSize: 10,
        pageNum: 1
      },
      currentPage4: 1,
      total: 0,
      formData:{
        surplusNumber: 0
      }

    }
  },
  created() {
    this.showList();
  },
  methods: {
    showByid(row){
      this.dialogFormVisible = true;
      this.formData.id = row.id;
      this.formData.surplusNumber = row.surplusNumber;
    },
    UpdateHistory(){
      hospitalUpdata(this.formData).then((res)=>{
        console.log(res);
        this.dialogFormVisible = false;
        this.$message.success("修改成功");
        this.showList();
      })

    },
    handleClick(id) {
      hospitalReser(id).then((res)=>{
        console.log(res);
        if(res.data.flag){
          this.$message.success("预约成功");
          this.showList();
        }else{
          this.$message.error(res.data.msg);
        }
      })

    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.form.pageSize = val;
      this.showList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.form.pageNum = val;
      this.showList();
    },
    onSubmit() {
      console.log('submit!');
    },
    showList(){
      hospitalList(this.form).then((res)=>{
        console.log(res);
        this.tableData = res.data.data.hospitalList.records;
        this.total = res.data.data.hospitalList.total;
        this.roleData = res.data.data.roleData;
        console.log(this.roleData)
      })

    },
  }
}
</script>

<style scoped>

</style>